buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.10.+'
    }
}

apply plugin: 'android'

repositories {
    mavenCentral()
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile project(':libs:libogg')
    compile project(':libs:common')
    compile project(':libs:showcase-view:library')
}

def getDate() {
    def date = new Date()
    def formattedDate = date.format('yyyyMMdd')
    return formattedDate.toInteger()
}

android {
    compileSdkVersion 19
    buildToolsVersion '19.1.0'

    defaultConfig {
        targetSdkVersion 19
        minSdkVersion 14
        versionCode getDate()
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }

    signingConfigs {
        debug {
            storeFile file(System.getProperty("user.home") + "/.android/debug.keystore")
        }

        release {
            // Save password to ~/.gradle/gradle.properties
            storeFile file(System.getProperty("user.home") + MC_ANDROID_STORE_PATH)
            storePassword MC_ANDROID_STORE_PASSWORD
            keyAlias "RainNoise"
            keyPassword MC_ANDROID_KEY_PASSWORD
        }
    }

    buildTypes {
        debug {
            versionNameSuffix "-DEBUG"
        }

        release {
            debuggable false
            jniDebugBuild false
            signingConfig signingConfigs.release

            applicationVariants.all { variant ->
                def file = variant.outputFile
                variant.outputFile = new File(file.parent, file.name.replace(".apk", "-" + defaultConfig.versionCode + ".apk"))
            }
        }
    }

    lintOptions {
        abortOnError false
    }

    sourceSets {
        main {
            manifest {
                srcFile 'AndroidManifest.xml'
            }
            java {
                srcDir 'src'
            }
            res {
                srcDir 'res'
            }
            assets {
                srcDir 'assets'
            }
            resources {
                srcDir 'src'
            }
        }
    }
}


tasks.withType(Compile) {
    options.encoding = "UTF-8"
}

// @from http://blog.csdn.net/look_down/article/details/17557031
task copyNativeLibs(type: Copy) {
    from fileTree(dir: 'libs', include: 'armeabi/*.so') into 'build/lib'
    from fileTree(dir: 'libs/libogg/libs', include: [ 'armeabi/*.so', 'armeabi-v7a/*.so', 'mips/*.so', 'x86/*.so' ] ) into 'build/lib'
}

tasks.withType(Compile) {
    compileTask -> compileTask.dependsOn copyNativeLibs
}

clean.dependsOn 'cleanCopyNativeLibs'

tasks.withType(com.android.build.gradle.tasks.PackageApplication) { pkgTask ->
   pkgTask.jniFolders = [new File(buildDir, 'lib')]
}

